import numpy as np
import matplotlib.pyplot as plt
from coommon import *


def gradient_descent(f, init_x, lr=0.01, step_num=100):
    x = init_x
    x_list = []
    for i in range(step_num):
        x_list.append(x.copy())
        grad = numerical_gradient(f, x)
        x -= lr * grad
    return x, np.array(x_list)

def f(x):
    return x[0]**2 + x[1]**2

if __name__ == '__main__':
    x = np.array([-23.0, 34.0])
    x, x_list = gradient_descent(f, x,0.01,1000)
    print(x)

    plt.scatter(x_list[:, 0], x_list[:, 1])
    plt.show()